package site.brood.common.log.feign;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import site.brood.common.core.web.AjaxJson;
import site.brood.common.log.pojo.LogLoginDto;
import site.brood.common.log.pojo.LogOperationDto;

/**
 * 日志服务降级处理
 */
@Slf4j
@Component
public class LogFallbackFactory implements FallbackFactory<LogFeign> {
    @Override
    public LogFeign create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new LogFeign(){

            @Override
            public AjaxJson<Boolean> operLogAdd(LogOperationDto logOperationDto, String source) {
                log.error("操作日志服务调用失败");
                return AjaxJson.createByBoolean(false);
            }

            @Override
            public AjaxJson<Boolean> loginLogAdd(LogLoginDto logLoginDto, String source) {
                log.error("登陆日志服务调用失败");
                return AjaxJson.createByBoolean(false);
            }
        };
    }
}
